package cn.git.socket;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @description: 线程池工具类
 * @program: bank-credit-sy
 * @author: lixuchun
 * @create: 2022-08-16 10:58:07
 */
public class ThreadPoolUtil {

    /**
     * 线程池线程名称
     */
    private static final String DICS_THREAD_POOL_PREFIX = "DICS-SOCKET";

    /**
     * 超时时间 单位毫秒
     */
    private static final int REQ_TIME_OUT = 10 * 1000;

    /**
     * 阻塞队列大小
     */
    private static final int QUEUE_SIZE = 200;

    /**
     * 核心线程池数量
     */
    private static final int CORE_THREAD_NUM = 5;

    /**
     * 最大线程池数量
     */
    private static final int MAX_THREAD_NUM = 20;

    /**
     * 线程池构造参数
     */
    public static ThreadPoolExecutor THREAD_POOL = new ThreadPoolExecutor(CORE_THREAD_NUM,
            MAX_THREAD_NUM,
            REQ_TIME_OUT,
            TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(QUEUE_SIZE),
            new OnlineThreadFactory(DICS_THREAD_POOL_PREFIX));
}
